<template>
	<view class="home">
		<navbar></navbar>
		<tab :list="tabList" :tabIndex="tabIndex" @tab="tab" @getTotalHeight="getHeight"></tab>
		<view class="home-list" style="background: gainsboro;">
			<list :tab="tabList" :activeIndex="activeIndex" @changed="change"></list>
		</view>
	</view>
</template>

<script>
	import {
		getLabel
	} from '@/common/mock/mock.js'
	import formItem from '../../uni_modules/uview-ui/libs/config/props/formItem';
	export default {
		data() {
			return {
				tabList: [],
				tabIndex: 0,
				activeIndex: 0
			}
		},
		onLoad() {
			this.getLabel();
		},
		methods: {
			change(current) {
				// console.log("当前swiper的值:",current);
				this.tabIndex = current;
				this.activeIndex
			},
			tab({
				data,
				index
			}) {
				// console.log(data, index)
				this.activeIndex = index;
			},
			getLabel() {
				// mock数据
				// getLabel().then((res) => {
				// 	// console.log(res)
				// 	// data.unshit({
				// 	// 	name: '全部'
				// 	// })
				// 	this.tabList = res
				// })

				// uniCloud云函数
				this.$api.get_label({
					name: 'get_label'
				}).then((res) => {
					const {
						data
					} = res
					// console.log('标签',data);
					data.unshift({
						name:'全部'
					})
					this.tabList = data
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		display: flex;
	}

	.home {
		display: flex;
		flex-direction: column;
		flex: 1;
		overflow: hidden;

		.home-list {
			flex: 1;
			box-sizing: border-box;
			// border: 1px red solid;
		}
	}
</style>